import { ref } from 'vue'
import { getOaEmpList as getOaEmpListApi } from '@/api/basic'

/**
 * OA员工列表服务
 */
export default function () {
  const getOaEmpListLoading = ref(false)
  const oaEmpList = ref<Array<BaseInfoAPIResponse.OaEmpListItem>>([])
  const getOaEmpListParam = ref({
    jobNumber: '',
    name: '',
  })

  const getOaEmpList = async () => {
    try {
      getOaEmpListLoading.value = true
      const res = await getOaEmpListApi(getOaEmpListParam.value)
      getOaEmpListLoading.value = false
      if (res.data.code === 20000) {
        oaEmpList.value = res.data.data.row
        return ''
      }

      return res.data.message
    } catch (error) {
      getOaEmpListLoading.value = false
      return '获取OA员工列表失败，请稍后重试'
    }
  }

  const resetGetOaEmpListParam = () => {
    getOaEmpListParam.value = {
      jobNumber: '',
      name: '',
    }
  }

  return {
    oaEmpList,
    getOaEmpListParam,
    getOaEmpListLoading,
    getOaEmpList,
    resetGetOaEmpListParam,
  }
}
